<?php
/**
 * @author Mazvv
 * @package Advertisesactivity
 */
class Advertisesactivity extends CRM_Controller {
	public function __construct(){
		parent::__construct();
		$this->a_identifier = 'advertisesactivity';
		$this->lang->load('advertisesactivity');
		$this->load->model('advertisesactivity_model');
		$this->load->model('filials_model');
		$this->load->model('advertisessources_model');
		
		$this->a_validation_rules['bdate'] = "required";
		$this->a_validation_rules['edate'] = "required";
		
		$this->a_validation_fields['bdate'] = $this->lang->line('BDATE');
		$this->a_validation_fields['edate'] = $this->lang->line('EDATE');
		$this->a_validation_fields['source'] = $this->lang->line('SOURCE');
		$this->a_validation_fields['filial'] = $this->lang->line('FILIAL');

		$this->a_validation_fields['descr'] = $this->lang->line('DESCR');
		$this->a_validation_fields['archive'] = $this->lang->line('ARCHIVE');
		$this->a_validation_fields['modifyDT'] = $this->lang->line('ARCHIVE');
		$this->validation->set_rules($this->a_validation_rules);
		$this->validation->set_fields($this->a_validation_fields);
		
		$this->objectsList['MENU_OBJECT'] = $this->menucontainer->RenderVerticalTreeMenu();
	}
	
	public function _remap($m_Name){
		switch ($m_Name) {
			default: $this->_index();
		}
	}
	
	protected function _index(){
		$this->objectsList['GRID_OBJECT'] = $this->_journal();
		$this->load->view('layouts/main_layout', $this->objectsList);
	}

	private function _journal(){
		if ($this->validation->run() == FALSE){
			$content = array();
			$content['title'] = $this->lang->line('DICTIONARY_TITLE'); 
			$content['bdate'] =  $this->RenderLabel('bdate');
			$data = array('name'=>'bdate', 'id'=>'bdate', 'size'=>'12', 'readonly'=>'readonly', 'value'=>$this->validation->bdate?$this->validation->bdate:'');
			$content['bdate_field'] =  form_input($data).$this->RenderCalendar('bdate');
			$content['edate'] =  $this->RenderLabel('edate');
			$data = array('name'=>'edate', 'id'=>'edate', 'size'=>'12', 'readonly'=>'readonly', 'value'=>$this->validation->edate?$this->validation->edate:'');
			$content['edate_field'] =  form_input($data).$this->RenderCalendar('edate');
			$content['source'] =  $this->RenderLabel('source');
			$content['source_field'] =  form_dropdown('source', $this->advertisessources_model->GetPairArr());
			$content['filial'] =  $this->RenderLabel('filial');
			$content['filial_field'] =  form_dropdown('filial', $this->filials_model->GetPairArr());
			return $this->load->view('reports/advertisesactivity/journal', $content, True);
		}
		$this->advertisesactivity_model->to_Excel();
	}
}

?>